home *** CD-ROM | disk | FTP | other *** search
/ DigitalVision: Spaced Out / DigitalVision: Spaced Out - Disc 1.iso / pc / data / images.dxr / Internal_10_Generic Useful Handlers.ls < prev    next >
Encoding:
Text File  |  2001-10-22  |  9.6 KB  |  448 lines

  1. global gurlpath
  2.  
  3. on getData fieldname
  4.   plist = [:]
  5.   numlines = the number of lines in field fieldname
  6.   numitems = the number of items in line 1 of field fieldname
  7.   repeat with i = 2 to numlines
  8.     tlist = [:]
  9.     repeat with j = 1 to numitems
  10.       var = item j of line i of field fieldname
  11.       s = item j of line 1 of field fieldname
  12.       addProp(tlist, symbol(s), var)
  13.     end repeat
  14.     if var <> EMPTY then
  15.       addProp(plist, symbol(item 1 of line i of field fieldname), tlist)
  16.     end if
  17.   end repeat
  18.   return plist
  19. end
  20.  
  21. on setData plist, delim
  22.   numlines = count(plist)
  23.   numitems = count(plist[1])
  24.   if ilk(plist) = #list then
  25.     tabledata = EMPTY
  26.   else
  27.     tabledata = "id" & delim
  28.   end if
  29.   line1 = plist[1]
  30.   repeat with i = 1 to numitems
  31.     tabledata = tabledata & string(getPropAt(line1, i))
  32.     if i <> numitems then
  33.       tabledata = tabledata & delim
  34.       next repeat
  35.     end if
  36.     tabledata = tabledata & RETURN
  37.   end repeat
  38.   repeat with i = 1 to numlines
  39.     if ilk(plist) = #list then
  40.       str = EMPTY
  41.     else
  42.       str = string(getPropAt(plist, i)) & delim
  43.     end if
  44.     repeat with j = 1 to numitems
  45.       if ilk(plist[i][j]) = #symbol then
  46.         str = str & "#" & string(plist[i][j])
  47.       else
  48.         str = str & plist[i][j]
  49.       end if
  50.       if j <> numitems then
  51.         str = str & delim
  52.       end if
  53.     end repeat
  54.     tabledata = tabledata & str & RETURN
  55.   end repeat
  56.   return tabledata
  57. end
  58.  
  59. on getData2 fieldname, delim, props
  60.   oldDel = the itemDelimiter
  61.   the itemDelimiter = delim
  62.   if props then
  63.     plist = [:]
  64.   else
  65.     plist = []
  66.   end if
  67.   numlines = the number of lines in field fieldname
  68.   numitems = the number of items in line 1 of field fieldname
  69.   repeat with i = 2 to numlines
  70.     tlist = [:]
  71.     repeat with j = 1 to numitems
  72.       var = item j of line i of field fieldname
  73.       s = item j of line 1 of field fieldname
  74.       addProp(tlist, symbol(s), var)
  75.     end repeat
  76.     if var <> EMPTY then
  77.       if props then
  78.         addProp(plist, symbol(item 1 of line i of field fieldname), tlist)
  79.         next repeat
  80.       end if
  81.       append(plist, tlist)
  82.     end if
  83.   end repeat
  84.   the itemDelimiter = oldDel
  85.   return plist
  86. end
  87.  
  88. on fixData plist
  89.   lastbutton = count(plist)
  90.   repeat with i = 1 to lastbutton
  91.     lastitem = count(plist[i])
  92.     repeat with j = 1 to lastitem
  93.       if value(plist[i][j]) = VOID then
  94.         if plist[i][j] = "0" then
  95.           plist[i][j] = 0
  96.         end if
  97.         next repeat
  98.       end if
  99.       plist[i][j] = value(plist[i][j])
  100.     end repeat
  101.   end repeat
  102.   return plist
  103. end
  104.  
  105. on makeList fieldname
  106.   numoflines = member(fieldname).line.count
  107.   tlist = []
  108.   repeat with i = 1 to numoflines
  109.     if member(fieldname).line[i] <> EMPTY then
  110.       add(tlist, member(fieldname).line[i])
  111.     end if
  112.   end repeat
  113.   return tlist
  114. end
  115.  
  116. on myGetPos sourcelist, prop
  117.   counter = 1
  118.   val = 0
  119.   repeat with i in sourcelist
  120.     if prop = getPropAt(sourcelist, counter) then
  121.       val = counter
  122.       exit repeat
  123.     end if
  124.     counter = counter + 1
  125.   end repeat
  126.   return val
  127. end
  128.  
  129. on check val, tlist
  130.   flag = 0
  131.   repeat with i in tlist
  132.     if i = val then
  133.       flag = 1
  134.       exit repeat
  135.     end if
  136.   end repeat
  137.   return flag
  138. end
  139.  
  140. on randomizelist theList
  141.   newlist = []
  142.   numofitems = count(theList)
  143.   repeat with i = 1 to numofitems
  144.     randompos = random(numofitems + 1 - i)
  145.     itemfound = getAt(theList, randompos)
  146.     add(newlist, itemfound)
  147.     deleteAt(theList, randompos)
  148.     numofitemsleft = numofitemsleft - 1
  149.   end repeat
  150.   return newlist
  151. end
  152.  
  153. on query dtable, val, sfield, rfield
  154.   tlist = []
  155.   repeat with record in dtable
  156.     if record[sfield] = val then
  157.       if listp(rfield) then
  158.         vtlist = [:]
  159.         repeat with f in rfield
  160.           addProp(vtlist, f, record[f])
  161.         end repeat
  162.         add(tlist, vtlist)
  163.         next repeat
  164.       end if
  165.       add(tlist, record[rfield])
  166.     end if
  167.   end repeat
  168.   return tlist
  169. end
  170.  
  171. on swapChar2 str, ch1, ch2, numToSwap
  172.   if voidp(numToSwap) then
  173.     numToSwap = the maxinteger
  174.   end if
  175.   num = length(str)
  176.   repeat with i = 1 to num
  177.     if char i of str = ch1 then
  178.       put ch2 into char i of str
  179.       numToSwap = numToSwap - 1
  180.       if numToSwap = 0 then
  181.         exit repeat
  182.       end if
  183.     end if
  184.   end repeat
  185.   return str
  186. end
  187.  
  188. on swapChar str, ch1, ch2
  189.   num = length(str)
  190.   repeat with i = 1 to num
  191.     if char i of str = ch1 then
  192.       put ch2 into char i of str
  193.     end if
  194.   end repeat
  195.   return str
  196. end
  197.  
  198. on removeChar2 str, charToRemove, numToRemove
  199.   if voidp(numToRemove) then
  200.     numToRemove = the maxinteger
  201.   end if
  202.   l = length(str)
  203.   newstr = EMPTY
  204.   repeat with i = 1 to l
  205.     c = char i of str
  206.     if c <> charToRemove then
  207.       newstr = newstr & c
  208.       next repeat
  209.     end if
  210.     numToRemove = numToRemove - 1
  211.     if numToRemove = 0 then
  212.       newstr = newstr & chars(str, i + 1, l)
  213.       exit repeat
  214.     end if
  215.   end repeat
  216.   return newstr
  217. end
  218.  
  219. on removeChar str, charToRemove
  220.   l = length(str)
  221.   newstr = EMPTY
  222.   repeat with i = 1 to l
  223.     c = char i of str
  224.     if c <> charToRemove then
  225.       newstr = newstr & c
  226.     end if
  227.   end repeat
  228.   return newstr
  229. end
  230.  
  231. on toUpperCase str
  232.   newstr = EMPTY
  233.   l = length(str)
  234.   repeat with i = 1 to l
  235.     chid = charToNum(str.char[i])
  236.     if (chid >= 97) and (chid <= 122) then
  237.       chid = chid - 32
  238.     end if
  239.     newstr = newstr & numToChar(chid)
  240.   end repeat
  241.   return newstr
  242. end
  243.  
  244. on toLowerCase str
  245.   newstr = EMPTY
  246.   l = length(str)
  247.   repeat with i = 1 to l
  248.     chid = charToNum(str.char[i])
  249.     if (chid >= 65) and (chid <= 90) then
  250.       chid = chid + 32
  251.     end if
  252.     newstr = newstr & numToChar(chid)
  253.   end repeat
  254.   return newstr
  255. end
  256.  
  257. on firstletterUpper str
  258.   newstr = toUpperCase(char 1 of str)
  259.   newstr = newstr & chars(str, 2, length(str))
  260.   return newstr
  261. end
  262.  
  263. on dummyString numofchs, ch
  264.   str = EMPTY
  265.   repeat with i = 1 to numofchs
  266.     str = str & ch
  267.   end repeat
  268.   return str
  269. end
  270.  
  271. on checkIfNumber numstr
  272.   len = length(numstr)
  273.   isnum = 1
  274.   repeat with i = 1 to len
  275.     thischar = charToNum(char i of numstr)
  276.     if (thischar >= 48) and (thischar <= 57) then
  277.       nothing()
  278.       next repeat
  279.     end if
  280.     isnum = 0
  281.     exit repeat
  282.   end repeat
  283.   return isnum
  284. end
  285.  
  286. on getPathDelim
  287.   if (the environment).runMode = "plugin" then
  288.     return "/"
  289.   else
  290.     if (the environment).platform contains "mac" then
  291.       return ":"
  292.     else
  293.       return "\"
  294.     end if
  295.   end if
  296. end
  297.  
  298. on getCastExt
  299.   mode = (the environment).runMode
  300.   case mode of
  301.     "author":
  302.       return ".cst"
  303.     "projector":
  304.       return ".cxt"
  305.     "plugin":
  306.       return ".cct"
  307.   end case
  308. end
  309.  
  310. on addMinutes begintime, gameduration
  311.   oldDelimiter = the itemDelimiter
  312.   the itemDelimiter = ":"
  313.   currenthours = integer(item 1 of begintime)
  314.   currentmins = integer(item 2 of begintime)
  315.   currentsecs = integer(item 3 of begintime)
  316.   the itemDelimiter = oldDelimiter
  317.   hours2add = integer(gameduration / 60)
  318.   minutes2add = integer(gameduration mod 60)
  319.   newhours = hours2add + currenthours
  320.   if (minutes2add + currentmins) > 59 then
  321.     newminutes = minutes2add + currentmins - 60
  322.     newhours = newhours + 1
  323.   else
  324.     newminutes = minutes2add + currentmins
  325.   end if
  326.   newsecs = currentsecs
  327.   if newhours > 23 then
  328.     newhours = newhours - 24
  329.   end if
  330.   if (newhours > -1) and (newhours < 10) then
  331.     newhours = "0" & newhours
  332.   end if
  333.   if (newminutes > -1) and (newminutes < 10) then
  334.     newminutes = "0" & newminutes
  335.   end if
  336.   if (newsecs > -1) and (newsecs < 10) then
  337.     newsecs = "0" & newsecs
  338.   end if
  339.   newtime = newhours & ":" & newminutes & ":" & newsecs
  340.   return newtime
  341. end
  342.  
  343. on timeDifference time1, time2
  344.   if time1 > time2 then
  345.     t1 = time1
  346.     t2 = time2
  347.   else
  348.     t1 = time2
  349.     t2 = time1
  350.   end if
  351.   oldDel = the itemDelimiter
  352.   the itemDelimiter = ":"
  353.   t1hours = integer(item 1 of t1)
  354.   t1mins = integer(item 2 of t1)
  355.   t1secs = integer(item 3 of t1)
  356.   t2hours = integer(item 1 of t2)
  357.   t2mins = integer(item 2 of t2)
  358.   t2secs = integer(item 3 of t2)
  359.   thours = t1hours - t2hours
  360.   tmins = t1mins - t2mins
  361.   tsecs = t1secs - t2secs
  362.   the itemDelimiter = oldDel
  363.   mins = (thours * 60) + tmins
  364.   secs = (mins * 60) + tsecs
  365.   return secs
  366. end
  367.  
  368. on pluraldetect t, str
  369.   if t = 1 then
  370.     tstr = str
  371.   else
  372.     tstr = str & "s"
  373.   end if
  374.   return tstr
  375. end
  376.  
  377. on SortOutQuotes sz
  378.   n = 1
  379.   repeat while n < length(sz)
  380.     if char n of sz = QUOTE then
  381.       put QUOTE & ""E&" & QUOTE into char n of sz
  382.       n = n + 9
  383.       next repeat
  384.     end if
  385.     n = n + 1
  386.   end repeat
  387.   return sz
  388. end
  389.  
  390. on propsplit plist
  391.   namelist = []
  392.   row1 = plist[1]
  393.   numofcols = count(row1)
  394.   repeat with i = 1 to numofcols
  395.     append(namelist, getPropAt(row1, i))
  396.   end repeat
  397.   numofrows = count(plist)
  398.   datalist = []
  399.   repeat with row = 1 to numofrows
  400.     tlist = []
  401.     repeat with col = 1 to numofcols
  402.       append(tlist, plist[row][col])
  403.     end repeat
  404.     append(datalist, tlist)
  405.   end repeat
  406.   return [namelist, datalist]
  407. end
  408.  
  409. on propjoin theList
  410.   newlist = []
  411.   namelist = theList[1]
  412.   datalist = theList[2]
  413.   numofcols = count(namelist)
  414.   numofrows = count(datalist)
  415.   repeat with rows = 1 to numofrows
  416.     tlist = [:]
  417.     repeat with cols = 1 to numofcols
  418.       addProp(tlist, namelist[cols], datalist[rows][cols])
  419.     end repeat
  420.     append(newlist, tlist)
  421.   end repeat
  422.   return newlist
  423. end
  424.  
  425. on setScreenData sideTitleText, mainColor, subColor
  426.   member("Side Title").text = sideTitleText
  427.   member("Side Title").foreColor = mainColor
  428.   member("Top Title0").foreColor = mainColor
  429.   member("Top Title1").foreColor = mainColor
  430.   member("Top Title2").foreColor = subColor
  431. end
  432.  
  433. on addProps Data, propslist
  434.   v = ilk(Data)
  435.   if v <> #propList then
  436.     newlist = [:]
  437.     Data = [:]
  438.   else
  439.     newlist = duplicate(Data)
  440.   end if
  441.   repeat with p in propslist
  442.     if myGetPos(Data, p) = 0 then
  443.       addProp(newlist, p, -1200)
  444.     end if
  445.   end repeat
  446.   return newlist
  447. end
  448.